package com.taru.service.impl;

import com.taru.dao.GardenMapper;
import com.taru.dao.PhotoMapper;
import com.taru.model.Garden;
import com.taru.model.Photo;
import com.taru.service.GardenService;
import com.taru.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GardenServiceImpl implements GardenService {
    @Autowired
    GardenMapper gardenMapper;
    @Autowired
    PhotoMapper photoMapper;


    @Override
    public int insertGarden(Garden garden, Photo photo) {
        String ID = Constant.UUID;
        int k = 0;
        garden.setGardenId(ID);
        int i = gardenMapper.insertGarden(garden);
        photo.setArticleId(ID);
        int j = photoMapper.insertPhoto(photo);
        if(i == 1 && j == 1){
            k = 1;
        }
        return  k;
    }

    @Override
    public int updateGardenById(Garden garden, Photo photo) {
        int k = 0;
        int i = gardenMapper.updateGardenById(garden);
        int j = photoMapper.updatePhotoById(photo);
        if(i == 1 && j == 1){
            k = 1;
        }
        return k;
    }

    @Override
    public int deleteGardenById(String gardenId) {
        return gardenMapper.deleteGardenById(gardenId);
    }

    @Override
    public Garden queryGardenById(String userId) {
        Garden garden = gardenMapper.queryGardenById(userId);
        garden.setPhoto(photoMapper.queryPhotoById(garden.getGardenId()));

        return garden;
    }
}
